var isNav, isIE
var offsetX, offsetY
var selectedObj 

var dragimg_width=100
var dragimg_height=100

var dragimg_startx=300
var dragimg_starty=150

function close_open(i)
{
	if(i=="cl")
	{
		document.all.picture1.style.visibility="hidden"
	}
	else
	{
		document.all.picture1.style.visibility="visible"
		if (document.all) 
		{
	
			document.all.picture1.style.posLeft=dragimg_startx
			document.all.picture1.style.posTop=dragimg_starty
		
		}
	
		if (document.layers) 
		{
		document.picture1.left=dragimg_startx
		document.picture1.top=dragimg_starty
		}
	}
	
}
////
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true
	} else {
		isIE = true
	}
}


function setZIndex(obj, zOrder) 
{
	obj.zIndex = zOrder
}


function shiftTo(obj, x, y) {
	if (isNav) {
		obj.moveTo(x,y)

	
	}
	else {
		obj.pixelLeft = x
		obj.pixelTop = y
	}
}

function setSelectedElem(evt) 
{
	if (isNav) 
	{
		var testObj
		for (var i = document.layers.length - 1; i >= 0; i--) 
		{
			testObj = document.layers[i]
			if (testObj.name=="picture1") 
			{
					selectedObj = testObj
					setZIndex(selectedObj, 1001)
					return
			}
		}
	} 
	else 
	{
		var imgObj = window.event.srcElement
		if (imgObj.parentElement.id.indexOf("picture1") != -1) 
		{
			selectedObj = imgObj.parentElement.style
			setZIndex(selectedObj,1001)
			return
		}
	}
	selectedObj = null
	return
}

function dragIt(evt)
 {
	if (selectedObj) 
	{
		if (isNav) 
		{
			shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY))
			//if(evt.pageX<=0 || evt.pageY<=0 || evt.pageY>475 || evt.pageX>1350)
			//{
			//shiftTo(selectedObj,300,70)
			//}

		} 
		else 
		{
			shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY))

			//if(window.event.clientX<=0 || window.event.clientY<=0 || window.event.clientY>475 || window.event.clientX>1350)
			//{
			//shiftTo(selectedObj,300,70)
			//}
			return false
		}
	}
}

function engage(evt) {
	setSelectedElem(evt)
	if (selectedObj) {
		if (isNav) {
			offsetX = evt.pageX - selectedObj.left
			offsetY = evt.pageY - selectedObj.top
		} else {
			offsetX = window.event.offsetX
			offsetY = window.event.offsetY
		}
	}
	return false
}

function release(evt) {
	if (selectedObj) {
		setZIndex(selectedObj, 1001)
		
		selectedObj = null
	}
}

function setNavEventCapture() {
	if (isNav) {
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
	}
}

function init() {
	if (isNav) {
		setNavEventCapture()
	}
	document.onmousedown = engage
	document.onmousemove = dragIt
	document.onmouseup = release
	if (document.all) {

		document.all.picture1.style.posLeft=dragimg_startx
		document.all.picture1.style.posTop=dragimg_starty

	}
	
	if (document.layers) {

		document.picture1.left=dragimg_startx
		document.picture1.top=dragimg_starty

	}
	
}
